package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.common.constant.ClueStatusConstants;
import com.qk.dto.club.*;
import com.qk.entity.Clue;
import com.qk.management.service.ClueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {

    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result getCluePoolList(CluePoolPageDTO dto) {
        return Result.success(clueService.getCluePoolList(dto));
    }

    @PutMapping("/false/{id}")
    public Result falseClue(@PathVariable Integer id, @RequestBody ClueFakeDTO dto) {
        dto.setId(id);
        clueService.updateFakeClue(dto);
        return Result.success();
    }

    @PutMapping("toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @PutMapping
    public Result updateClueInfoById(@RequestBody UpdateClueInfoDTO dto){
        clueService.updateClueInfoById(dto);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueById(@PathVariable Integer id) {
        return Result.success(clueService.getClueById(id));
    }


    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueId(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .userId(userId)
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .updateTime(LocalDateTime.now())
                .build());
        return Result.success();
    }

    @GetMapping
    public Result getCluePageList(CluePageDTO dto) {
        return Result.success(clueService.getCluePageList(dto));
    }


    @PostMapping
    public Result addClub(@RequestBody ClueDTO dto) {
        clueService.addClub(dto);
        return Result.success();
    }

}
